/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.ShipperProcessor;

import com.sun.Entity.Shippingorder;
import com.sun.Facade.ShippingorderFacadeLocal;
import exceptions.AmountNotCorrespondingException;
import exceptions.UnknownOrderException;
import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ejb.Stateless;

/**
 *
 * @author Jean-Michel
 */
@WebService()
@Stateless()
public class PayOrderWS {

    @EJB
    private ShippingorderFacadeLocal shippingorderFacade;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "PayOrder")
    public void PayOrder(
            @WebParam(name = "OrderID") String OrderID,
            @WebParam(name = "Amount") double Amount)
            throws
            AmountNotCorrespondingException,
            UnknownOrderException {

        // Verification OrderID existance
        Shippingorder Order = shippingorderFacade.find(OrderID);
        if (Order == null) {
            throw new UnknownOrderException();
        }

        // Verificate valid amount
        if (Amount != Order.getAmount()) {
            throw new AmountNotCorrespondingException();
        }

        Order.setIspaid(1);
        shippingorderFacade.edit(Order);
    }
}
